package top.eggcode.component.office.pattern;

import org.apache.poi.xwpf.usermodel.XWPFDocument;
import top.eggcode.common.lang.MapUtil;
import top.eggcode.component.office.WordRender;

import java.util.HashMap;
import java.util.Map;

/**
 * Word模板拆分模式
 * 说明：{
 * 现在的设计是，把所有的数据放到一个Map集合， 在模式方法中进行拆分。也就是说一个模式只适用于一个模板；
 * 每个类型的模板，渲染方法不一样。如果需要增加模式，在本类添加对应的静态方法即可，有三个参数供你使用；
 * toWordTemplate(in,
 * out,
 * props,
 * wordRenderPattern::interviewCheckForm);
 * }
 *
 * @author JiaQi Ding
 */
public class WordTemplate {
    /**
     * 面试审核表
     *
     * @param document 文档
     * @param props    数据
     */
    public static void interviewCheckForm(WordRender wordRender, XWPFDocument document, Map<String, String> props) {
        Map<String, String> symbolProps = new HashMap<>(5);
        symbolProps.put("studentType_1", props.get("studentType_1"));
        symbolProps.put("studentType_2", props.get("studentType_2"));
        // 编译符号
        wordRender.toSymbol(document, symbolProps, "Wingdings 2");

        props.remove("studentType_1");
        props.remove("studentType_2");
        // 编译段落
        wordRender.toText(document, props);
        // 编译填充式表格
        wordRender.toTextInTable(document, props);
    }

    /**
     * 录取通知书
     *
     * @param document 文档
     * @param props    数据
     */
    public static void admissionLetter(WordRender wordRender, XWPFDocument document, Map<String, String> props) {
        Map<String, String> tableProps = new HashMap<>(10);
        String[] keyNames = {
                "nationalityNameInCn",
                "applyNoInCn",
                "nationalityNameInEn",
                "applyNoInEn",
                "scholarshipNoInCn",
                "scholarshipNoInEn",
                "scholarshipDescInCn",
                "scholarshipDescInEn"
        };
        MapUtil.moveEntrySet(props, tableProps, keyNames);

        Map<String, String> barcodeProps = new HashMap<>(10);
        MapUtil.moveEntrySet(props, barcodeProps, new String[]{"imageBarcodeInCn", "imageBarcodeInEn"});

        wordRender.toBarcodeInTable(document, barcodeProps, 140, 14);
        wordRender.toTextInTable(document, tableProps);
        // 编译段落
        wordRender.toText(document, props);
    }

    /**
     * 电子卡
     *
     * @param document 文档
     * @param props    数据
     */
    public static void stuEcard(WordRender wordRender, XWPFDocument document, Map<String, String> props) {
        Map<String, String> tableProps = new HashMap<>(10);

        // 图片
        Map<String, String> imageProps = new HashMap<>(10);
        MapUtil.moveEntrySet(props, imageProps, new String[]{"stuPhoto"});

        // 表格
        String[] keyNames = {"stuName", "stuNo"};
        MapUtil.moveEntrySet(props, tableProps, keyNames);

        // 编译图片
        wordRender.toImageInTable(document, imageProps);
        // 编译表格
        wordRender.toTextInTable(document, tableProps);
        // 编译段落
        wordRender.toText(document, props);
    }

    /**
     * jw201or202
     *
     * @param document 文档
     * @param props    数据
     */
    public static void jw201or202(WordRender wordRender, XWPFDocument document, Map<String, String> props) {
        Map<String, String> tableProps = new HashMap<>(10);

        // 图片
        Map<String, String> imageProps = new HashMap<>(10);
        MapUtil.moveEntrySet(props, imageProps, new String[]{});

        // 表格
        String[] keyNames = {"schoolName", "signY", "signM", "signD",
                "nameFamily", "nameGiven", "passportNo", "nationality", "gender", "marital",
                "birthDateY", "birthDateM", "birthDateD", "birthPlace",
                "homeContact", "highestDegree", "career", "companyOrSch",
                "typeStudent", "major", "studyStartY", "studyStartM", "studyEndY", "studyEndM",
                "registerEndY", "registerEndM", "registerEndD",

                "hanbuSchName", "hanbuStudyStartY", "hanbuStudyStartM", "hanbuStudyEndY", "hanbuStudyEndM",
                "cscNo", "fundsIsFull", "fundsIsTuition", "fundsIsLodging", "fundsIsLiving", "fundsIsInsurance", "fundsOther",

                "reference", "guarantorAffair", "guarantorEconomy", "fundsIsScholarship", "fundsIsSelfSponsored", "fundsIsOther",
        };
        MapUtil.moveEntrySet(props, tableProps, keyNames);

        // 编译图片
        wordRender.toImageInTable(document, imageProps);
        // 编译表格
        wordRender.toTextInTable(document, tableProps);
        // 编译段落
        wordRender.toText(document, props);
    }
}
